package com.wecon.dianping.util;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Weikang  Wang
 * @program: com.wecon.dianping.util
 * @description: MD5加密
 * @date 2020/3/17 10:09
 */
public class EncodeByMd5 {

    /**
     * MD5加密
     *
     * @param str 明文
     * @return 密文
     * @throws NoSuchAlgorithmException     /
     * @throws UnsupportedEncodingException /
     */
    public static String encode(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        BASE64Encoder base64Encoder = new BASE64Encoder();
        return base64Encoder.encode(messageDigest.digest(str.getBytes("utf-8")));
    }

}
